package com.k.demo.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.k.demo.entity.ConstantTermKind;
import com.k.demo.entity.GoodOrder;
import com.k.demo.entity.GoodOrderDetail;
import com.k.demo.service.ConstantTermKindService;

@RestController
@RequestMapping("/constantkind")
public class ConstantTermKindController {
	
	@Autowired
	private ConstantTermKindService constantTermKindService;
	
	
	//一下ConstantTermKind  简称为CTK

	/**
	 * 返回所有常数项类别
	 * url /constantkind/all
	 * @author shy
	 */
	@RequestMapping("/all")
	public Object all() {
		
		Map<String,Object> map = new HashMap<String, Object>();
		
		map.put("ctkList", constantTermKindService.getAll());
		
		return map;
	}
	
	/**
	 * 根据id查找
	 * url /constantkind/searchbyid
	 * @author shy
	 */
	@RequestMapping("/searchbyid")
	public Object getById(@RequestBody Map<String,Object> map) {
		
		Map<String,Object> rmap = new HashMap<String, Object>();
		
		rmap.put("searchResult", constantTermKindService.getById((int)map.get("constant_term_kind_id")));
		
		return rmap;
		
	}
	
	/**
	 * 增加新的常数项类别对象
	 * url /constantkind/add
	 * @author shy
	 */
	@RequestMapping("/add")
	public Object addCTK(@RequestBody ConstantTermKind constantTermKind) {
		
		Map<String,Object> map = new HashMap<String, Object>();
		
		map.put("addResult", constantTermKindService.addConstantTermKind(constantTermKind));
		
		return map;
	}
	
	/**
	 * 根据id删除
	 * url /constantkind/delete
	 * @author shy
	 */
	@RequestMapping("/delete")
	public Object deleteCTK(@RequestBody Map<String,Object> map) {
		
		Map<String,Object> rmap = new HashMap<String, Object>();
		
		rmap.put("deleteResult", constantTermKindService.falseDeleteById((int)map.get("constant_term_kind_id")));
		
		return rmap;
	}
	
	/**
	 * 修改常数项类别表
	 * url /constantkind/modify
	 * @author shy
	 */
	@RequestMapping("/modify")
	public Object modifyCTK(@RequestBody ConstantTermKind constantTermKind) {
		
		Map<String,Object> map = new HashMap<String, Object>();
		
		map.put("modifyResult", constantTermKindService.modifyConstantTermKind(constantTermKind));
		
		return map;
	}
	
	
	/**
	 * 批量删除
	 * url /constantkind/deletegroup
	 * @author shy
	 */
	@RequestMapping("/deletegroup")
	public Object deleteCTKs(@RequestBody String deleteGroup) {
		
		JSONObject jsonObject = JSON.parseObject(deleteGroup);
		
		List<Integer> deleteList = JSON.parseArray(jsonObject.getString("deleteList"), Integer.class);
		
		Map<String,Object> map = new HashMap<String, Object>();
		
		map.put("deleteGroupResult", constantTermKindService.deleteByGroup(deleteList));
		
		return map;
	}
	
	/**
	 * 页面所有常数项类别分页显示
	 * url /constantkind/all
	 * @author shy
	 */
	@RequestMapping("/all/page")
	public Object allpage(@RequestBody Map<String,Object> map) {
		
		Map<String,Object> rmap = new HashMap<String, Object>();
		
		rmap.put("constantkindList", constantTermKindService.getPage((int)map.get("pageNum"),(int)map.get("pageSize")));
		
		return rmap;
	}
	
	/**
	 * 公告管理的模糊查询(公告内容的检索)
	 * url/constantkind/searchByContent
	 * @author shy
	 */
	@RequestMapping("/searchByContent")
	public Object searchNoticeByName(@RequestBody Map<String,Object> map) {
		
		Map<String,Object> rmap = new HashMap<String, Object>();
		
		rmap.put("searchByNameList", constantTermKindService.getPageByName((int)map.get("pageNum"),(int)map.get("pageSize"),(String)map.get("content")));
		
		return rmap;
		
	}
	

}
